go to previous page   go to home page   go to next page hear noise

Answer:

C:\users\default>java ArrayEg2

cell 3: 0.0
cell 2: 2.98
cell 1: 1.43

More Complicated Example

Here is a more complicated example:

class ArrayEg3
{
  public static void main ( String[] args )
  {
    double[] val = new double[4];  

    val[0] =  1.5;
    val[1] = 10.0;
    val[2] = 15.5;

    int j  = 3;
    val[j] = val[j-1] + val[j-2];   // same as val[3] = val[2] + val[1]

    System.out.println( "val[" + j + "] == " + val[j] );
 
   }
}

QUESTION 10:

What does the above program print out?

val [ ] ==